<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/head"></head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <th:block th:replace="common/header"></th:block>
    <th:block th:replace="common/nav"></th:block>

    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                修改密码
            </h1>
            <ol class="breadcrumb">
                <li><a href="/index"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">修改密码</a></li>
            </ol>
        </section>

        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box box-info">
                        <div class="box-header with-border">
                            <h3 class="box-title">修改密码</h3>
                        </div>

                        <form class="form-horizontal" action="/updatePassword" method="post" >
                            <input type="hidden" name="userId" id="userId" th:value="${xsUserDto.userId}" />
                            <div class="box-body">
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">账号</label>

                                        <div class="col-sm-7">
                                            <input name="userName" type="text" id="userName" class="form-control" required="required" AUTOCOMPLETE="off" th:value="${xsUserDto.userName}"/>
                                            <span id="userNameSpan"></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="box-body">
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">手机号</label>

                                        <div class="col-sm-7">
                                            <input name="phoneNum" type="text" id="phoneNum" class="form-control" required="required" AUTOCOMPLETE="off" th:value="${xsUserDto.phoneNum}" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" maxlength="11"/>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="box-body">
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">原密码</label>

                                        <div class="col-sm-7">
                                            <input name="passWord" type="password" id="passWord" class="form-control" required="required" AUTOCOMPLETE="off" />
                                            <span id="span"></span>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="box-body">
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">新密码*</label>

                                        <div class="col-sm-7">
                                            <input name="upPassWord" type="password" id="upPassWord" class="form-control" required="required" AUTOCOMPLETE="off" />
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="box-body">
                                <div class="col-xs-6">
                                    <div class="form-group">
                                        <label class="col-sm-4 control-label">再次输入新密码*</label>

                                        <div class="col-sm-7">
                                            <input id="encrypt2" type="password" name="encrypt2" class="form-control" required="required" AUTOCOMPLETE="off" />
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="box-footer">
                                <a href="/index" class="btn btn-default">放  弃</a>
                                <button  type="button" onclick="updatePwd()" class="btn btn-info pull-right submit">修  改</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <th:block th:replace="common/footer"></th:block>
</div>

<th:block th:replace="common/script"></th:block>
<script type="text/javascript">

    function updatePwd(){
        var userId = $("#userId").val();
        var userName = $("#userName").val();
        var phoneNum = $("#phoneNum").val();
        var passWord = $("#passWord").val();
        var upPassWord = $("#upPassWord").val();
        var encrypt2 = $("#encrypt2").val();
        if(userName==''){
            alert('请输入账号');
        }else if(phoneNum=='') {
            alert('请输入手机号');
        }else if(passWord=='') {
            alert('请输入原密码');
        } else if(upPassWord=='') {
            alert('请输入新密码');
        } else if(encrypt2=='') {
            alert('请再次输入新密码');
        } else {
            if(upPassWord == encrypt2){
                $.ajax({
                    url:"/updatePassword?userId="+userId+"&passWord="+passWord+"&upPassWord="+upPassWord+"&userName="+userName+"&phoneNum="+phoneNum,
                    type: "post",
                    dataType: "json",
                    success: function (data) {
                        alert(data.message);
                        $("#encrypt").val("");
                        $("#passWord").val("");
                        $("#upPassWord").val("");
                        if(data.statusCode==200){
                            window.location.href = '/login';
                        }
                    }
                });
            }else{
                alert("两次输入的密码不一致，请重新输入！");
            }
        }
    }


</script>
</body>
</html>
